package com.yuanluludev.app.room

import androidx.lifecycle.MutableLiveData
import com.yuanluludev.app.room.student.Student
import com.yuanluludev.lib_base.base.BaseViewModel

class RoomViewModel : BaseViewModel() {

    private val roomRes by lazy { RoomRepository() }

    val studentList = MutableLiveData<ArrayList<Student>>()

    fun insertStudent(student: Student) {
        launch(block = { roomRes.insertStudent(student) })
    }

    fun getAllStudent() {
        launch(block = {
            studentList.value = roomRes.getAllStudent() as ArrayList<Student>
        })
    }

    fun queryAllStudentOrderByUidDesc() {
        launch(block = {
            studentList.value = roomRes.queryAllStudentOrderByUidDesc() as ArrayList<Student>
        })
    }

    fun deleteStudentByID(uid: Long) {
        launch(block = {
            roomRes.deleteStudentByID(uid)
        })
    }

    fun updateStudent(student: Student) {
        launch(block = {
            roomRes.updateStudent(student)
        })
    }

}